package com.yc.dao;

import java.util.List;
import java.util.Map;

public class ContactsDao {
	/**
	 * 添加联系人
	 * @param account
	 * @return
	 */
	public int add(String account, String account1) {
		DBHelper db = new DBHelper();
		String sql = "insert into tb_contact values(seq_contact_id.nextval, ?,  ?)";
		return db.update(sql, account, account1);
	}
	/**
	 * 删除数据
	 * @param account
	 * @return
	 */
	public int delete(String account) {
		DBHelper db = new DBHelper();
		String sql = "delete from tb_contact where t_rname = ?";
		return db.update(sql, account);
	}
	public int delete1(String account) {
		DBHelper db = new DBHelper();
		String sql = "delete from (select t_id,  t_rname, u_cardid, u_tel from tb_user u right join tb_contact c on u.u_name = c.t_rname) where t_rname = ?";
		return db.update(sql, account);
	}
	/**
	 * 查询所有联系人信息
	 * @return
	 */
	public List<Map<String, String>> finds(String account){
		DBHelper db = new DBHelper();
		String sql = "select t_id,  t_rname, u_cardid, u_tel from tb_user u right join tb_contact c on u.u_name = c.t_rname where c.u_name = ?";
		return db.finds(sql, account);
	}
	/**
	 * 查询当前用户所有联系人名字
	 * @return
	 */
	public List<Map<String, String>> findTRname(String account){
		DBHelper db = new DBHelper();
		String sql = "select t_rname from tb_contact where u_name = ?";
		return db.finds(sql, account);
	}
}
